package com.shrcl.engineerprocess.domain.impl;

import com.shrcl.engineerprocess.domain.Engineer;
import com.shrcl.engineerprocess.domain.EngineerWorkOrder;
import com.shrcl.engineerprocess.domain.EngineerWorkOrderCriteria;
import com.shrcl.engineerprocess.domain.EngineerWorkOrderStatus;
import com.shrct.businessprocess.project.RCProject;
import edu.fudan.mylang.pf.query.HQLBasedPagedQueryCriteria;
import java.util.Collection;
import java.util.Date;
import org.hibernate.Query;

public class EngineerWorkOrderCriteriaImpl extends HQLBasedPagedQueryCriteria<EngineerWorkOrder> implements EngineerWorkOrderCriteria {
  private String info;
  
  public String getInfo() {
    return this.info;
  }
  
  public EngineerWorkOrderCriteria setInfo(final String info) {
    this.info = info;
    return this;			
    
  }
  
  private Engineer engineer;
  
  public Engineer getEngineer() {
    return this.engineer;
  }
  
  public EngineerWorkOrderCriteria setEngineer(final Engineer engineer) {
    this.engineer = engineer;
    return this;			
    
  }
  
  private Collection<EngineerWorkOrderStatus> mulstatus;
  
  public Collection<EngineerWorkOrderStatus> getMulstatus() {
    return this.mulstatus;
  }
  
  public EngineerWorkOrderCriteria setMulstatus(final Collection<EngineerWorkOrderStatus> mulstatus) {
    this.mulstatus = mulstatus;
    return this;			
    
  }
  
  private Date startDate;
  
  public Date getStartDate() {
    return this.startDate;
  }
  
  public EngineerWorkOrderCriteria setStartDate(final Date startDate) {
    this.startDate = startDate;
    return this;			
    
  }
  
  private Date endDate;
  
  public Date getEndDate() {
    return this.endDate;
  }
  
  public EngineerWorkOrderCriteria setEndDate(final Date endDate) {
    this.endDate = endDate;
    return this;			
    
  }
  
  private RCProject cbdProject;
  
  public RCProject getCbdProject() {
    return this.cbdProject;
  }
  
  public EngineerWorkOrderCriteria setCbdProject(final RCProject cbdProject) {
    this.cbdProject = cbdProject;
    return this;			
    
  }
  
  private Engineer manager;
  
  public Engineer getManager() {
    return this.manager;
  }
  
  public EngineerWorkOrderCriteria setManager(final Engineer manager) {
    this.manager = manager;
    return this;			
    
  }
  
  protected String buildHQLFrom() {
    return " from com.shrcl.engineerprocess.domain.impl.EngineerWorkOrderImpl this ";
  }
  
  protected String buildHQLBody() {
    String hql = "where 1 = 1 ";
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInfo()) && !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInfo()) ){
    	hql += " and ((this.sid  LIKE :info) or (this.projectJob.engineerProject.tscCostEstimation.project.name  LIKE :info))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getMulstatus()) ){
    	hql += " and (this.Status  IN (:mulstatus))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getEngineer()) ){
    	hql += " and ((this.engineer) = (:engineer))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getStartDate()) ){
    	hql += " and ((this.startDate) >= (:startDate))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getEndDate()) ){
    	hql += " and ((this.endDate) < (:endDate))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCbdProject()) ){
    	hql += " and ((this.projectJob.engineerProject.tscCostEstimation.project) = (:cbdProject))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getManager()) && !edu.fudan.mylang.pf.query.QueryUtil.isNull(getManager()) ){
    	hql += " and (((this.projectJob.engineerProject.projectManager) = (:manager)) or ((this.projectJob.engineerProject.techLeader) = (:manager)))" ;
    }
    return hql;
    
  }
  
  public void initOrderBys() {
    
  }
  
  protected void fillParameter(final Query query) {
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getInfo())){
    	query.setParameter("info",getInfo()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getEngineer())){
    	query.setParameter("engineer",getEngineer()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getMulstatus())){
    	query.setParameterList("mulstatus",getMulstatus()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getStartDate())){
    	query.setParameter("startDate",getStartDate()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getEndDate())){
    	query.setParameter("endDate",getEndDate()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCbdProject())){
    	query.setParameter("cbdProject",getCbdProject()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getManager())){
    	query.setParameter("manager",getManager()) ;
    }			
    
  }
  
  protected Boolean isDistinct() {
    return false;
  }
  
  public EngineerWorkOrderCriteriaImpl() {
    initOrderBys();
  }
}
